package com.dlc.felear.xiaoensale.application;

import android.content.Context;
import android.content.Intent;

import com.dlc.felear.xiaoensale.activity.FirstActivity;
import com.dlc.felear.xiaoensale.helper.UpLoadInfo;

public class CrashHandler implements Thread.UncaughtExceptionHandler {

    private Context context;

    public CrashHandler(Context context) {
        this.context = context;
    }

    @Override
    public void uncaughtException(Thread t, Throwable e) {
        e.printStackTrace();
        showToast(t);
        UpLoadInfo.getInstance().syncSendWarnInfo( "异常信息：" + e.getMessage(), UpLoadInfo.TYPE_LOG);
    }

    /**
     * 操作
     *
     * @param thread
     */
    private void showToast(Thread thread) {
//        restartApp();
    }

    /**
     * 重启应用
     */
    private void restartApp() {
        Intent intent = new Intent(context, FirstActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(intent);
        android.os.Process.killProcess(android.os.Process.myPid());
    }
}
